

package org.come.until;

import com.tool.tcpimg.UIUtils;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.ImageObserver;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.swing.ImageIcon;
import org.come.Frame.ZhuFrame;
import org.come.entity.Good;
import org.come.entity.Goodstable;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;

public class DDGoodUntil {
	public static List<Good> ddgood = new ArrayList<>();
	public static int ys = 1;

	public DDGoodUntil() {
	}

	public static void draw(Graphics g, int x, int y) {
		g.setFont(UIUtils.TEXT_FONT);
		g.setColor(Color.red);
		int p = (ys - 1) * 42;

		for(int i = 0; i < 42; ++i) {
			if (p >= ddgood.size()) {
				return;
			}

			Good good = ddgood.get(p);
			int row = i % 6;
			int col = i / 6;
			ImageIcon icon = GoodsListFromServerUntil.imgpath(good.getGoodstable().getSkin());
			g.drawImage(icon.getImage(), x + row * 51 + 2, y + col * 51 + 2, 45, 45, null);
			if (!EquipTool.isEquip(good.getGoodstable().getType())) {
				g.setFont(new Font("宋体", 1, 14));
				g.setColor(Color.WHITE);
				g.drawString("" + good.getGoodstable().getUsetime(), x + 3 + row * 51, y + 13 + col * 51);
			}

			++p;
		}

	}

	public static void addddgood(Goodstable goodstable) {
		for(int i = 0; i < ddgood.size(); ++i) {
			if (ddgood.get(i).getGoodstable().getRgid().compareTo(goodstable.getRgid()) == 0) {
				ddgood.get(i).setGoodstable(goodstable);
				return;
			}
		}

		Good good = new Good();
		good.setGoodstable(goodstable);
		ddgood.add(good);
	}

	public static void Retrieve(int i) {
		Goodstable goodstable = getgood(i);
		if (goodstable != null) {
			int sum = GoodsListFromServerUntil.Surplussum("" + goodstable.getType(), "" + goodstable.getGoodsid(), goodstable.getUsetime());
			if (sum <= 0) {
				ZhuFrame.getZhuJpanel().addPrompt2("你背包已满");
			} else {
				ddgood.remove((ys - 1) * 42 + i);
				String mes = Agreement.getAgreement().RecivePawnAgreement(goodstable.getRgid().toString());
				SendMessageUntil.toServer(mes);
			}
		}
	}

	public static Goodstable getgood(int i) {
		i += (ys - 1) * 42;
		return i >= ddgood.size() ? null : ddgood.get(i).getGoodstable();
	}

	public static void zhengli() {
		Collections.sort(ddgood);
	}
}
